package cn.structure.binarytree.bst;

/**
 * 树节点定义类
 *
 * @author dunlingzi
 */
public class BsTreeNode<T extends Comparable<T>> {

    /**
     * 关键字（键值）
     */
    T nodeKey;

    /**
     * 左节点引用
     */
    BsTreeNode<T> left;

    /**
     * 右节点引用
     */
    BsTreeNode<T> right;

    /**
     * 父节点
     */
    BsTreeNode<T> parent;

    /**
     * 不能存在空参构造函数
     */
    public BsTreeNode() {
        this.nodeKey = null;
        this.left = null;
        this.right = null;
        this.parent = null;
    }

    public BsTreeNode(T data) {
        this.nodeKey = data;
        this.left = null;
        this.right = null;
        // 只有数据，那应该是单节点
        this.parent = null;
    }

    /**
     * 树根节点构造
     *
     * @param left  左子树
     * @param right 右子树
     * @param data  节点值
     */
    public BsTreeNode(BsTreeNode<T> left, BsTreeNode<T> right, T data) {
        this.right = right;
        this.left = left;
        this.nodeKey = data;
        this.parent = null;
    }

    /**
     * 指定节点的构造方法  ？？？存在否
     *
     * @param left   左子树
     * @param right  右子树
     * @param data   节点值
     * @param parent 父节点
     */
    public BsTreeNode(BsTreeNode<T> left, BsTreeNode<T> right, T data, BsTreeNode<T> parent) {
        this.right = right;
        this.left = left;
        this.nodeKey = data;
        this.parent = parent;
    }

    public T getNodeKey() {
        return nodeKey;
    }

    public void setNodeKey(T nodeKey) {
        this.nodeKey = nodeKey;
    }

    public BsTreeNode<T> getLeft() {
        return left;
    }

    public void setLeft(BsTreeNode<T> left) {
        this.left = left;
    }

    public BsTreeNode<T> getRight() {
        return right;
    }

    public void setRight(BsTreeNode<T> right) {
        this.right = right;
    }

    public BsTreeNode<T> getParent() {
        return parent;
    }

    public void setParent(BsTreeNode<T> parent) {
        this.parent = parent;
    }
}
